package com.hzlj.position.locate.dao;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fz.common.base.converter.QueryWrapperConverterPlus;
import com.hzlj.position.locate.common.dto.messageToday.MessageTodayQueryResultDTO;
import com.hzlj.position.locate.common.model.MessageToday;
import com.hzlj.position.locate.mapper.MessageTodayMapper;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 当天消息通知(MessageToday)表操作类
 *
 * @author makejava
 * @date 2024-01-10 16:38:24
 */
@Repository
public class MessageTodayDao extends ServiceImpl<MessageTodayMapper, MessageToday> {
    @Resource
    private MessageTodayMapper messageTodayMapper;


    public void delete(Date now) {
        LambdaQueryWrapper<MessageToday> updateWrapper = new QueryWrapper<MessageToday>().lambda()
                .lt(MessageToday::getBelongDay,  DateUtil.beginOfDay(now));
        this.remove(updateWrapper);
    }


    public List<MessageToday> listMessageToday(Date now) {
        return QueryWrapperConverterPlus.of(messageTodayMapper)
                .list(MessageToday.class, null, q -> q
                        .eq(MessageToday::getBelongDay, DateUtil.beginOfDay(now))
                        .le(MessageToday::getNoticeTime, now)
                );
    }

}

